home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / ui / OGC / test.c < prev   
Encoding:
C/C++ Source or Header  |  1990-03-06  |  1.9 KB  |  91 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1989, Tera Computer Company
  5.  **/
  6.  
  7. /* Somewhat nonconvincing test for garbage collector.                */
  8. /* Note that this intentionally uses the worlds worst implementation */
  9. /* of cons.  It eats up gobs of memory in an attempt to break the    */
  10. /* collector.  Process size should grow to about 1.5 Meg and stay    */
  11. /* there.                                                            */
  12. /* Should take about 25 seconds (2 minutes) to run on a              */
  13. /* Sun 3/60 (Vax 11/750)                                             */
  14. /* (The Vax does reasonably well here because the compiler assures   */
  15. /* longword pointer alignment.)                                      */
  16.  
  17. # include <stdio.h>
  18. # include "cons.h"
  19.  
  20. /* Return reverse(x) concatenated with y */
  21. sexpr reverse1(x, y)
  22. sexpr x, y;
  23. {
  24.     if (null(x)) {
  25.         return(y);
  26.     } else {
  27.         return( reverse1(cdr(x), cons(car(x), y)) );
  28.     }
  29. }
  30.  
  31. sexpr reverse(x)
  32. sexpr x;
  33. {
  34.     return( reverse1(x, nil) );
  35. }
  36.  
  37. sexpr ints(low, up)
  38. int low, up;
  39. {
  40.     if (low > up) {
  41.     return(nil);
  42.     } else {
  43.         return(cons(low, ints(low+1, up)));
  44.     }
  45. }
  46.  
  47. void print_int_list(x)
  48. sexpr x;
  49. {
  50.     if (null(x)) {
  51.         printf("NIL\n");
  52.     } else {
  53.         printf("%d", car(x));
  54.         if (!null(cdr(x))) {
  55.             printf(", ");
  56.             print_int_list(cdr(x));
  57.         } else {
  58.             printf("\n");
  59.         }
  60.     }
  61. }
  62.  
  63. /* Try to force a to be strangely aligned */
  64. struct {
  65.   char dummy;
  66.   sexpr aa;
  67. } A;
  68. #define a A.aa
  69.  
  70. main()
  71. {
  72.     int i;
  73.     sexpr b;
  74.  
  75.     gc_init();
  76.     a = ints(1, 100);
  77.     b = ints(1, 50);
  78.     print_int_list(a);
  79.     print_int_list(b);
  80.     print_int_list(reverse(a));
  81.     print_int_list(reverse(b));
  82.     for (i = 0; i < 100; i++) {
  83.         b = reverse(reverse(b));
  84.     }
  85.     print_int_list(a);
  86.     print_int_list(b);
  87.     print_int_list(reverse(a));
  88.     print_int_list(reverse(b));
  89. }
  90.  
  91.